package org.etherframework.tests.features.wiring
{
	import org.etherframework.core.EtherConfig;
	import org.etherframework.common.local;
	import org.etherframework.common.wire.IWire;
	import org.etherframework.common.wire.IWiring;
	import org.etherframework.core.IModule;
	import org.etherframework.tests.features.wiring.config.ConfigWithCustomProcessor;
	import org.etherframework.tests.features.wiring.models.NotifiableWirableModel;
	import org.etherframework.tests.features.wiring.models.WirableModel;
	import org.etherframework.tests.utils.TestUtility;
	import org.hamcrest.assertThat;
	import org.hamcrest.object.isFalse;
	import org.hamcrest.object.isTrue;
	import org.hamcrest.object.nullValue;

	public class when_unwiring_target
	{	
		private static var _testUtility:TestUtility = new TestUtility();
		private static var _module:IModule;
		private static var _w:IWiring;
		
		private static var _wirable:WirableModel;
		private static var _notifiableWirable:NotifiableWirableModel;
		private static var _wirableWire:IWire;
		private static var _notifiableWire:IWire;
		
		[BeforeClass]
		public static function setUpBeforeClass():void
		{
			var wire:IWire;
			// Here we use cust config to set custom metatag processor.
			// See MyEtherConfig.
			var config:EtherConfig = new ConfigWithCustomProcessor();
			
			_module = _testUtility.createModule(config);
			_w = _module.wiring;
			
			_wirable = new WirableModel();
			_notifiableWirable = new NotifiableWirableModel();
			
			_wirableWire = _w.createWire(_wirable);
			_wirableWire.initialize(_testUtility.createEther(_module));
			_wirableWire.wire();
			
			_notifiableWire = _w.createWire(_notifiableWirable);
			_notifiableWire.initialize(_testUtility.createEther(_module));
			_notifiableWire.wire();
			
			_wirableWire.unwire();
			_notifiableWire.unwire();
		}
		
		[AfterClass]
		public static function tearDownAfterClass():void
		{
			_testUtility.dispose();
		}
		
		[Test(order=1)]
		public function it_should_be_unwired():void
		{
			assertThat(_wirable.hello, nullValue());
			assertThat(_wirable.wantSomeHello, nullValue());
			assertThat(_notifiableWirable.hello, nullValue());
			assertThat(_notifiableWirable.local::localHello, nullValue());
			assertThat(_notifiableWirable.unwireNotified, isTrue());
			
			assertThat(_wirableWire.wired, isFalse());
			assertThat(_notifiableWire.wired, isFalse());
		}
	}
}